package com.wangxiang.shop.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wangxiang.shop.product.entity.ShopBaseEntity;
import com.wangxiang.shop.product.service.ShopBaseService;
import com.wangxiang.common.utils.PageUtils;
import com.wangxiang.common.utils.R;



/**
 * 
 *
 * @author wangxiang
 * @email 2293672863@qq.com
 * @date 2022-03-04 11:20:08
 */
@RestController
@RequestMapping("product/shopbase")
public class ShopBaseController {
    @Autowired
    private ShopBaseService shopBaseService;


    /**
     * add,添加
     */
    @RequestMapping("/add")
    public R add(@RequestBody ShopBaseEntity shopBase){
        if (shopBase.getName() == null | shopBase.getName() == " "){
            return R.error("请正确填写");
        }
        boolean add = shopBaseService.add(shopBase.getName());
        if (!add){
            return R.error("添加失败,或已存在");
        }

        return R.ok().put("data",shopBase.getName()+"插入成功").put("code",600);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = shopBaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		ShopBaseEntity shopBase = shopBaseService.getById(id);

        return R.ok().put("shopBase", shopBase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ShopBaseEntity shopBase){
		shopBaseService.save(shopBase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ShopBaseEntity shopBase){
		shopBaseService.updateById(shopBase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		shopBaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
